From eb6b0d62813e3927a809aa26a4f68c432fcd31dd Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Mon, 23 Jun 2014 19:09:12 -0700 Subject: [PATCH] Rename cargo-compile to cargo-build --- Makefile | 2 +- src/bin/{cargo-compile.rs => cargo-build.rs} | 4 +-- src/bin/cargo.rs | 18 ++++------ src/cargo/ops/cargo_rustc.rs | 2 +- tests/test_cargo_compile.rs | 36 ++++++++++---------- tests/test_cargo_compile_git_deps.rs | 14 ++++---- tests/test_cargo_compile_path_deps.rs | 20 +++++------ 7 files changed, 45 insertions(+), 51 deletions(-) rename src/bin/{cargo-compile.rs => cargo-build.rs} (93%) diff --git a/Makefile b/Makefile index bededdd1d..057a5e7a7 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ DESTDIR ?= /usr/local # Link flags to pull in dependencies BINS = cargo \ - cargo-compile \ + cargo-build \ cargo-read-manifest \ cargo-rustc \ cargo-verify-project \ diff --git a/src/bin/cargo-compile.rs b/src/bin/cargo-build.rs similarity index 93% rename from src/bin/cargo-compile.rs rename to src/bin/cargo-build.rs index c097f6f2b..8a0f06581 100644 --- a/src/bin/cargo-compile.rs +++ b/src/bin/cargo-build.rs @@ -1,4 +1,4 @@ -#![crate_id="cargo-compile"] +#![crate_id="cargo-build"] #![feature(phase)] extern crate cargo; @@ -24,7 +24,7 @@ pub struct Options { update_remotes: bool } -hammer_config!(Options "Compile the current project", |c| { +hammer_config!(Options "Build the current project", |c| { c.short("update_remotes", 'u') }) diff --git a/src/bin/cargo.rs b/src/bin/cargo.rs index 0508d556a..d8427326e 100644 --- a/src/bin/cargo.rs +++ b/src/bin/cargo.rs @@ -32,10 +32,7 @@ struct ProjectLocation { fn execute() { debug!("executing; cmd=cargo; args={}", os::args()); - let (cmd, args) = match process(os::args()) { - Ok((cmd, args)) => (cmd, args), - Err(err) => return handle_error(err, &mut shell(false)) - }; + let (cmd, args) = process(os::args()); match cmd.as_slice() { "config-for-key" => { @@ -52,7 +49,7 @@ fn execute() { }, "--help" | "-h" | "help" | "-?" => { println!("Commands:"); - println!(" compile # compile the current project\n"); + println!(" build # compile the current project\n"); let (_, options) = hammer::usage::(false); println!("Options (for all commands):\n\n{}", options); @@ -76,14 +73,11 @@ fn execute() { } } -fn process(args: Vec) -> CliResult<(String, Vec)> { - let args: Vec = Vec::from_slice(args.tail()); - let head = try!(args.iter().nth(0).require(|| { - human("No subcommand found") - }).map_err(|err| CliError::from_boxed(err, 1))).to_str(); - let tail = Vec::from_slice(args.tail()); +fn process(args: Vec) -> (String, Vec) { + let mut args = Vec::from_slice(args.tail()); + let head = args.shift().unwrap_or("--help".to_str()); - Ok((head, tail)) + (head, args) } #[deriving(Encodable)] diff --git a/src/cargo/ops/cargo_rustc.rs b/src/cargo/ops/cargo_rustc.rs index b28984080..3357ff886 100644 --- a/src/cargo/ops/cargo_rustc.rs +++ b/src/cargo/ops/cargo_rustc.rs @@ -3,7 +3,7 @@ use std::io; use std::io::{File, IoError}; use std::str; -use core::{MultiShell, Package, PackageSet, Target}; +use core::{Package, PackageSet, Target}; use util; use util::{CargoResult, ChainError, ProcessBuilder, internal, human, CargoError}; use util::{Config}; diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index 4e7cb58e8..28a7d0225 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -30,7 +30,7 @@ test!(cargo_compile_simple { .file("Cargo.toml", basic_bin_manifest("foo").as_slice()) .file("src/foo.rs", main_file(r#""i am foo""#, []).as_slice()); - assert_that(p.cargo_process("cargo-compile"), execs()); + assert_that(p.cargo_process("cargo-build"), execs()); assert_that(&p.root().join("target/foo"), existing_file()); let target = p.root().join("target"); @@ -44,7 +44,7 @@ test!(cargo_compile_with_invalid_manifest { let p = project("foo") .file("Cargo.toml", ""); - assert_that(p.cargo_process("cargo-compile"), + assert_that(p.cargo_process("cargo-build"), execs() .with_status(101) .with_stderr("Cargo.toml is not a valid manifest\n\n\ @@ -58,7 +58,7 @@ test!(cargo_compile_with_invalid_manifest2 { foo = bar "); - assert_that(p.cargo_process("cargo-compile"), + assert_that(p.cargo_process("cargo-build"), execs() .with_status(101) .with_stderr("could not parse input TOML\n\ @@ -68,7 +68,7 @@ test!(cargo_compile_with_invalid_manifest2 { test!(cargo_compile_without_manifest { let p = project("foo"); - assert_that(p.cargo_process("cargo-compile"), + assert_that(p.cargo_process("cargo-build"), execs() .with_status(102) .with_stderr("Could not find Cargo.toml in this directory or any \ @@ -82,7 +82,7 @@ test!(cargo_compile_with_invalid_code { let target = realpath(&p.root().join("target")).assert(); - assert_that(p.cargo_process("cargo-compile"), + assert_that(p.cargo_process("cargo-build"), execs() .with_status(101) .with_stderr(format!("\ @@ -101,7 +101,7 @@ test!(cargo_compile_with_warnings_in_the_root_package { .file("Cargo.toml", basic_bin_manifest("foo").as_slice()) .file("src/foo.rs", "fn main() {} fn dead() {}"); - assert_that(p.cargo_process("cargo-compile"), + assert_that(p.cargo_process("cargo-build"), execs() .with_stderr("\ src/foo.rs:1:14: 1:26 warning: code is never used: `dead`, #[warn(dead_code)] \ @@ -158,7 +158,7 @@ test!(cargo_compile_with_warnings_in_a_dep_package { let bar = realpath(&p.root().join("bar")).assert(); let main = realpath(&p.root()).assert(); - assert_that(p.cargo_process("cargo-compile"), + assert_that(p.cargo_process("cargo-build"), execs() .with_stdout(format!("{} bar v0.5.0 (file:{})\n\ {} foo v0.5.0 (file:{})\n", @@ -238,7 +238,7 @@ test!(cargo_compile_with_nested_deps_shorthand { } "#); - p.cargo_process("cargo-compile") + p.cargo_process("cargo-build") .exec_with_output() .assert(); @@ -314,7 +314,7 @@ test!(cargo_compile_with_nested_deps_longhand { } "#); - assert_that(p.cargo_process("cargo-compile"), execs()); + assert_that(p.cargo_process("cargo-build"), execs()); assert_that(&p.root().join("target/foo"), existing_file()); @@ -340,7 +340,7 @@ test!(custom_build { .file("src/foo.rs", r#" fn main() { println!("Hello!"); } "#); - assert_that(build.cargo_process("cargo-compile"), + assert_that(build.cargo_process("cargo-build"), execs().with_status(0)); @@ -359,7 +359,7 @@ test!(custom_build { .file("src/foo.rs", r#" fn main() {} "#); - assert_that(p.cargo_process("cargo-compile"), + assert_that(p.cargo_process("cargo-build"), execs().with_status(0) .with_stdout(format!(" Compiling foo v0.5.0 (file:{})\n", p.root().display())) @@ -381,7 +381,7 @@ test!(custom_build_failure { .file("src/foo.rs", r#" fn main() { fail!("nope") } "#); - assert_that(build.cargo_process("cargo-compile"), execs().with_status(0)); + assert_that(build.cargo_process("cargo-build"), execs().with_status(0)); let mut p = project("foo"); @@ -399,7 +399,7 @@ test!(custom_build_failure { .file("src/foo.rs", r#" fn main() {} "#); - assert_that(p.cargo_process("cargo-compile"), + assert_that(p.cargo_process("cargo-build"), execs().with_status(101).with_stderr(format!("\ Could not execute process `{}` (status=101) --- stderr @@ -430,7 +430,7 @@ test!(custom_build_env_vars { "#, p.root().join("target").display(), p.root().join("target/deps").display())); - assert_that(build.cargo_process("cargo-compile"), execs().with_status(0)); + assert_that(build.cargo_process("cargo-build"), execs().with_status(0)); p = p @@ -447,7 +447,7 @@ test!(custom_build_env_vars { .file("src/foo.rs", r#" fn main() {} "#); - assert_that(p.cargo_process("cargo-compile"), execs().with_status(0)); + assert_that(p.cargo_process("cargo-build"), execs().with_status(0)); }) test!(custom_build_in_dependency { @@ -473,7 +473,7 @@ test!(custom_build_in_dependency { "#, p.root().join("target/deps").display(), p.root().join("target/deps").display())); - assert_that(build.cargo_process("cargo-compile"), execs().with_status(0)); + assert_that(build.cargo_process("cargo-build"), execs().with_status(0)); p = p @@ -507,7 +507,7 @@ test!(custom_build_in_dependency { .file("bar/src/bar.rs", r#" pub fn bar() {} "#); - assert_that(p.cargo_process("cargo-compile"), + assert_that(p.cargo_process("cargo-build"), execs().with_status(0)); }) @@ -529,7 +529,7 @@ test!(many_crate_types { .file("src/foo.rs", r#" pub fn foo() {} "#); - assert_that(p.cargo_process("cargo-compile"), + assert_that(p.cargo_process("cargo-build"), execs().with_status(0)); let files = fs::readdir(&p.root().join("target")).assert(); diff --git a/tests/test_cargo_compile_git_deps.rs b/tests/test_cargo_compile_git_deps.rs index a5ae21687..aad1c3ddf 100644 --- a/tests/test_cargo_compile_git_deps.rs +++ b/tests/test_cargo_compile_git_deps.rs @@ -84,7 +84,7 @@ test!(cargo_compile_simple_git_dep { let root = project.root(); let git_root = git_project.root(); - assert_that(project.cargo_process("cargo-compile"), + assert_that(project.cargo_process("cargo-build"), execs() .with_stdout(format!("{} git repository `file:{}`\n\ {} dep1 v0.5.0 (file:{})\n\ @@ -165,7 +165,7 @@ test!(cargo_compile_with_nested_paths { .file("src/parent.rs", main_file(r#""{}", dep1::hello()"#, ["dep1"]).as_slice()); - p.cargo_process("cargo-compile") + p.cargo_process("cargo-build") .exec_with_output() .assert(); @@ -215,7 +215,7 @@ test!(recompilation { main_file(r#""{}", bar::bar()"#, ["bar"]).as_slice()); // First time around we should compile both foo and bar - assert_that(p.cargo_process("cargo-compile"), + assert_that(p.cargo_process("cargo-build"), execs().with_stdout(format!("{} git repository `file:{}`\n\ {} bar v0.5.0 (file:{})\n\ {} foo v0.5.0 (file:{})\n", @@ -224,7 +224,7 @@ test!(recompilation { COMPILING, p.root().display()))); // Don't recompile the second time - assert_that(p.process("cargo-compile"), + assert_that(p.process("cargo-build"), execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\ {} foo v0.5.0 (file:{})\n", FRESH, git_project.root().display(), @@ -235,13 +235,13 @@ test!(recompilation { pub fn bar() { println!("hello!"); } "#).assert(); - assert_that(p.process("cargo-compile"), + assert_that(p.process("cargo-build"), execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\ {} foo v0.5.0 (file:{})\n", FRESH, git_project.root().display(), FRESH, p.root().display()))); - assert_that(p.process("cargo-compile").arg("-u"), + assert_that(p.process("cargo-build").arg("-u"), execs().with_stdout(format!("{} git repository `file:{}`\n\ {} bar v0.5.0 (file:{})\n\ {} foo v0.5.0 (file:{})\n", @@ -257,7 +257,7 @@ test!(recompilation { git_project.process("git").args(["commit", "-m", "test"]).exec_with_output() .assert(); - assert_that(p.process("cargo-compile").arg("-u"), + assert_that(p.process("cargo-build").arg("-u"), execs().with_stdout(format!("{} git repository `file:{}`\n\ {} bar v0.5.0 (file:{})\n\ {} foo v0.5.0 (file:{})\n", diff --git a/tests/test_cargo_compile_path_deps.rs b/tests/test_cargo_compile_path_deps.rs index f994e0371..412c81748 100644 --- a/tests/test_cargo_compile_path_deps.rs +++ b/tests/test_cargo_compile_path_deps.rs @@ -72,7 +72,7 @@ test!(cargo_compile_with_nested_deps_shorthand { } "#); - p.cargo_process("cargo-compile") + p.cargo_process("cargo-build") .exec_with_output() .assert(); @@ -117,20 +117,20 @@ test!(no_rebuild_dependency { pub fn bar() {} "#); // First time around we should compile both foo and bar - assert_that(p.cargo_process("cargo-compile"), + assert_that(p.cargo_process("cargo-build"), execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\ {} foo v0.5.0 (file:{})\n", COMPILING, bar.display(), COMPILING, p.root().display()))); // This time we shouldn't compile bar - assert_that(p.process("cargo-compile"), + assert_that(p.process("cargo-build"), execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\ {} foo v0.5.0 (file:{})\n", FRESH, bar.display(), FRESH, p.root().display()))); p.build(); // rebuild the files (rewriting them in the process) - assert_that(p.process("cargo-compile"), + assert_that(p.process("cargo-build"), execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\ {} foo v0.5.0 (file:{})\n", COMPILING, bar.display(), @@ -190,14 +190,14 @@ test!(deep_dependencies_trigger_rebuild { .file("baz/src/baz.rs", r#" pub fn baz() {} "#); - assert_that(p.cargo_process("cargo-compile"), + assert_that(p.cargo_process("cargo-build"), execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\ {} bar v0.5.0 (file:{})\n\ {} foo v0.5.0 (file:{})\n", COMPILING, baz.display(), COMPILING, bar.display(), COMPILING, p.root().display()))); - assert_that(p.process("cargo-compile"), + assert_that(p.process("cargo-build"), execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\ {} bar v0.5.0 (file:{})\n\ {} foo v0.5.0 (file:{})\n", @@ -213,7 +213,7 @@ test!(deep_dependencies_trigger_rebuild { File::create(&p.root().join("baz/src/baz.rs")).write_str(r#" pub fn baz() { println!("hello!"); } "#).assert(); - assert_that(p.process("cargo-compile"), + assert_that(p.process("cargo-build"), execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\ {} bar v0.5.0 (file:{})\n\ {} foo v0.5.0 (file:{})\n", @@ -226,7 +226,7 @@ test!(deep_dependencies_trigger_rebuild { extern crate baz; pub fn bar() { println!("hello!"); baz::baz(); } "#).assert(); - assert_that(p.process("cargo-compile"), + assert_that(p.process("cargo-build"), execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\ {} bar v0.5.0 (file:{})\n\ {} foo v0.5.0 (file:{})\n", @@ -289,14 +289,14 @@ test!(no_rebuild_two_deps { .file("baz/src/baz.rs", r#" pub fn baz() {} "#); - assert_that(p.cargo_process("cargo-compile"), + assert_that(p.cargo_process("cargo-build"), execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\ {} bar v0.5.0 (file:{})\n\ {} foo v0.5.0 (file:{})\n", COMPILING, baz.display(), COMPILING, bar.display(), COMPILING, p.root().display()))); - assert_that(p.process("cargo-compile"), + assert_that(p.process("cargo-build"), execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\ {} bar v0.5.0 (file:{})\n\ {} foo v0.5.0 (file:{})\n", -- 2.30.2